package com.yunsc.shop.controller.product;

import com.yunsc.common.base.BaseContext;
import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.product.dto.QueryGoodsDTO;
import com.yunsc.product.entity.YunscGoodsServiceEntity;
import com.yunsc.product.service.YunscGoodsService;
import com.yunsc.product.service.YunscGoodsServiceService;
import com.yunsc.product.vo.GoodsDetailVO;
import com.yunsc.product.vo.GoodsInfoVO;
import com.yunsc.shop.utils.ClientInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 商品基本信息接口
 * @date: 2024-04-14 20:53
 */
@Api(tags = "商品信息管理", value = "商品基本信息接口")
@RestController
@RequestMapping("goods")
public class GoodsController {

    @Resource
    private YunscGoodsService goodsService;
    @Resource
    private YunscGoodsServiceService goodsServiceService;
    @Resource
    private ClientInfoUtils clientInfoUtils;


    /**
     * 查询商品列表
     */
    @ApiOperation("查询商品列表接口")
    @GetMapping("/list")
    public Result<Map<String, Object>> list(QueryGoodsDTO params) {
        if (params == null) {
            params = new QueryGoodsDTO();
        }
        Integer currentStoreId = clientInfoUtils.getCurrentStoreId();
        PageResult<GoodsInfoVO> page = goodsService.queryShopGoodsList(params, currentStoreId);
        return Result.resultPageList(page);
    }


    /**
     * 根据id查询商品信息
     */
    @ApiOperation("根据id查询商品详细信息")
    @GetMapping("/specData")
    public Result queryGoodsSpecData(@RequestParam("goodsId") Integer goodsId) {
        GoodsDetailVO yoshopGoods = goodsService.queryGoodsSpecData(goodsId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("specData", yoshopGoods);
        return Result.ok(map);
    }

    /**
     * 根据id查询商品信息
     */
    @ApiOperation("根据id查询商品详细信息")
    @GetMapping("/detail")
    public Result queryGoodsDetail(@RequestParam("goodsId") Integer goodsId) {
        GoodsDetailVO goods = goodsService.queryGoodsDetailById(goodsId);
        if (goods == null){
            return Result.error("很抱歉，商品信息不存在");
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("detail", goods);
        return Result.ok(map);
    }

    /**
     * 商品服务与承诺列表
     */
    @ApiOperation("查询服务与承诺列表")
    @GetMapping("/service/list")
    public Result<?> goodsServiceList(@RequestParam(required = false) Map<String, Object> params) {
        Integer currentStoreId = clientInfoUtils.getCurrentStoreId();
        PageResult<YunscGoodsServiceEntity> pageUtils = goodsServiceService.queryGoodsServiceList(params, currentStoreId);
        return Result.resultList(pageUtils.getData());
    }






}
